package au.com.carboncycle.gb.engine.entities;

import java.awt.Dimension;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;

import au.com.carboncycle.gb.engine.graphics.NullImageObserver;

public abstract class Sprite {

	protected static final NullImageObserver NIO = new NullImageObserver();
	
	protected int currPicIdx;

	protected Image[][] sheetRightFacing;
	protected Image[][] sheetLeftFacing;
	
	protected int maxPicIdx;
	protected Image currPic;
	protected Point position;

	public Sprite(Image[][] sheetRightFacing, Image[][] sheetLeftFacing, int initialPicIdx, Point initialPosition) {
		this.sheetRightFacing = sheetRightFacing;
		this.sheetLeftFacing = sheetLeftFacing;
		this.currPicIdx = initialPicIdx;
		this.position = initialPosition;
		this.maxPicIdx = sheetRightFacing.length-1;
	}

	public Image getCurrentImage() {
		return getCurrentSheet()[currPicIdx][0];
	}
	

	public Point getCurrentPosition() {
		return position;
	}

	public Rectangle2D getBounds() {
		return calculateBounds();
	}
	
	private Rectangle2D calculateBounds() {
		return new Rectangle(position, new Dimension(getCurrentImage().getWidth(NIO), getCurrentImage().getHeight(NIO)));
	}
	
	protected abstract Image[][] getCurrentSheet();

	protected Rectangle calculateNewBoundsForMoveTo(Point newPosition) {
		return new Rectangle(newPosition, new Dimension(getCurrentImage().getWidth(NIO), getCurrentImage().getHeight(NIO)));
	}


}